home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13556 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: access4.digex.net!not-for-mail
  2. From: ell@access4.digex.net (Ell)
  3. Newsgroups: comp.lang.c++,comp.lang.c,comp.object,comp.software-eng
  4. Subject: Re: Pointers are hacks in c++ (portablity hackers etc)
  5. Followup-To: comp.lang.c++,comp.lang.c,comp.object,comp.software-eng
  6. Date: 26 Mar 1996 02:31:43 GMT
  7. Organization: The Universe
  8. Message-ID: <4j7kuf$2ur@news4.digex.net>
  9. References: <4ikb6kINN1is@mayne.ugrad.cs.ubc.ca> <DoI5Ao.AyJ@assip.csasyd.oz>
  10. NNTP-Posting-Host: access4.digex.net
  11. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  12.  
  13. jason (jabaker@grail.cba.csuohio.edu) wrote:
  14. :...
  15. : I think c++ programmers fear pointers precisely because C++ does
  16. : nothing to solve the memory management problems of C.  
  17.  
  18. I do not think intermediate and advanced C++ programmers "fear 
  19. pointers".  They use them all the time.
  20.  
  21. : Let's say I've
  22. : built my list of pointers on the stack using the following macro:
  23. :   #define Stack_new(_T, _ARGS) \
  24. :   (void *_v = alloca(sizeof(_T)), new(_v) _T _ARGS)
  25. :
  26. : How should the list cells be destroyed:
  27.  
  28. Using a macro in this way with C++ is unnecessary in most cases.  One 
  29. simply 'news' a cell into existence and if you are using "smart pointers", 
  30. or a single object to register, you can keep track via reference counting.
  31.  
  32. : [ways to delete and keep track of objects elided]
  33. : So, there are two questions.  How was next allocated -- this can be
  34. : solved by ensuring that next always comes from the heap.  
  35.  
  36. 'next' should _never_ be a 'local' stack based structure.
  37.  
  38. : And, does
  39. : anything else refer to next -- this can't be solved with a reference
  40. : count, we are dealing with a linked list of arbitrary length, it can
  41. : only be solved by ensuring that there are no other references.
  42.  
  43. I don't see how reference counting heap based objects, which register 
  44. themselves in a central place, does not allow effective gc in C++.
  45.  
  46. Elliott
  47.